using UnityEngine;
using System.Collections;

public class LeafRazorBehave : MonoBehaviour {
	
	int time;
	float vx, vz;
	public Vector3 target = Vector3.zero;
	
	// Use this for initialization
	void Start () {
		this.transform.Rotate(90, 0, 0);
		time = 0;
		vz = 0;
		vx = 0.5f;
	}
	
	// Update is called once per frame
	void Update () {
		if(time > 120){
			DestroyObject(this.gameObject);
		}else if(time > 60){
			this.transform.Translate(Vector3.left*vx);
			vx += 0.2f;
			time += 1;
		}else{
			time += 1;
			if(vx > 0){
				vz -= 0.01f;
			}else{
				vz += 0.01f;
			}
			vz *= 0.99f;
			vx += vz;
			this.transform.Translate(0, vx, 0.08f);
			this.transform.Rotate(0, vx*2, 0);
		}
		if(target != Vector3.zero){
			this.transform.LookAt(target);
			this.transform.Rotate(90, 90, 0);
		}
	}
}
